/**
 * 
 */
package com.res.system.properties;

import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.res.common.controller.StoreFrontController;
import com.res.system.utils.SimulatorUtilities;

/**
 * @author da40188
 */
public class PropertyManager {

    @Resource(name = "sam6catalogapimapping")
    private Properties catalogMappingProperties;

    @Resource(name = "sourcecatalogapi")
    private Properties sourcecatalogProperties;

    @Resource(name = "discountapi")
    private Properties discountapiProperties;

    @Resource(name = "catalogbrowsapi")
    private Properties catalogBrowsingProperties;

    @Resource(name = "administratorapi")
    private Properties adminProperties;

    @Resource(name = "retailcatalogapi")
    private Properties retailcatalogapiProperties;

    @Resource(name = "simulator")
    private Properties simulatorProperties;

    @Resource(name = "systemConfig")
    private Properties configProperties;

    @Resource(name = "executormapping")
    private Properties executorMappingProperties;

    private static final Logger logger = Logger.getLogger(PropertyManager.class);

    public PropertyManager() {

    }

    public void load() {

        loadConfigurationProperties();

        // Set catalog Mapping Category
        final Map<String, String> catalogMappingPropertyMap = SimulatorUtilities.convertPropertyIntoMap(catalogMappingProperties);
        PropertySelector.getInstance().update("sam6catalogapimapping", catalogMappingPropertyMap);

        final Set<Object> catalogMappingKeySet = catalogMappingProperties.keySet();

        for (final Object object : catalogMappingKeySet) {

            if (object.toString().equals("RetailCatalogAPI")) {

                PropertySelector.getInstance().update("RetailCatalogAPI", SimulatorUtilities.convertPropertyIntoMap(retailcatalogapiProperties));

            } else if (object.toString().equals("DiscountAPI")) {

                PropertySelector.getInstance().update("DiscountAPI", SimulatorUtilities.convertPropertyIntoMap(discountapiProperties));

            } else if (object.toString().equals("CatalogBrowseAPI")) {

                PropertySelector.getInstance().update("CatalogBrowseAPI", SimulatorUtilities.convertPropertyIntoMap(catalogBrowsingProperties));

            } else if (object.toString().equals("AdministarorAPI")) {

                PropertySelector.getInstance().update("AdministarorAPI", SimulatorUtilities.convertPropertyIntoMap(adminProperties));

            } else if (object.toString().equals("SourceCatalogAPI")) {

                PropertySelector.getInstance().update("SourceCatalogAPI", SimulatorUtilities.convertPropertyIntoMap(sourcecatalogProperties));

            }
        }

    }

    private void loadConfigurationProperties() {

        // system configuration properties.
        final Map<String, String> configPropertyMap = SimulatorUtilities.convertPropertyIntoMap(configProperties);
        PropertySelector.getInstance().update("configProperties", configPropertyMap);
        // simulator properties
        final Map<String, String> simulatorPropertyMap = SimulatorUtilities.convertPropertyIntoMap(simulatorProperties);
        PropertySelector.getInstance().update("simulatorProperties", simulatorPropertyMap);

        // executor mapping properties
        final Map<String, String> executorMappingPropertyMap = SimulatorUtilities.convertPropertyIntoMap(executorMappingProperties);
        PropertySelector.getInstance().update("executorMappingProperties", executorMappingPropertyMap);
    }

}
